﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using Public;
using BLL;
using System.Windows.Forms.DataVisualization.Charting;

namespace QLNhanKhau
{
    public partial class frmBaocao : DevComponents.DotNetBar.Metro.MetroForm
    {

        public frmBaocao()
        {
            InitializeComponent();
            this.Location = new Point(0, 0);
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Thoát không lưu", "Thoát", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (result == DialogResult.Yes)
            {
                this.MdiParent = null;
                this.Dispose();
             
            }
        }

        private void frmBaocao_Load(object sender, EventArgs e)
        {
            List<DanTocPublic> dt = DanTocBLL.LoadBieuDoDanToc();
            chart1.Series["DanToc"].Points.DataBindXY(dt, "MaDT", dt, "SL");
            //chart1.Data
            for (int i = 0; i< chart1.Series[0].Points.Count();i++)
            {
                chart1.Series[0].Points[i].LegendText = dt[i].TenDanToc + ": #VALY";
                //chart1.Series[0].Points[i].Label = ;
            }
            chart1.Legends.Add(new Legend("Stores"));
            chart1.Series[0].ChartType = SeriesChartType.Pie;
            chart1.Series[0]["PieLabelStyle"] = "Outside";
            chart1.Series[0]["PieLineColor"] = "Black";

            chart1.Series[0].Label = "#PERCENT{P0}";
            chart1.Series[0].Font = new Font("Segoe UI", 8.0f, FontStyle.Bold);
            chart1.Series[0].ChartType = SeriesChartType.Pie;
            chart1.Series[0]["PieLabelStyle"] = "Outside";
            chart1.Series[0].Legend = "Stores";
            chart1.Legends[0].Docking = Docking.Bottom;
            //char ton giáot
            List<TonGiaoPublic> tg = TonGiaoBLL.LoadBieuDoTonGiao();
            chart2.Series["TonGiao"].Points.DataBindXY(tg, "MaTG", tg, "SL");
            //chart1.Data
            for (int i = 0; i < chart2.Series[0].Points.Count(); i++)
            {
                chart2.Series[0].Points[i].LegendText = tg[i].TenTonGiao + ": #VALY";
                //chart1.Series[0].Points[i].Label = ;
            }
            chart2.Legends.Add(new Legend("Stores"));
            chart2.Series[0].ChartType = SeriesChartType.Pie;
            chart2.Series[0]["PieLabelStyle"] = "Outside";
            chart2.Series[0]["PieLineColor"] = "Black";

            chart2.Series[0].Label = "#PERCENT{P0}";
            chart2.Series[0].Font = new Font("Segoe UI", 8.0f, FontStyle.Bold);
            chart2.Series[0].ChartType = SeriesChartType.Pie;
            chart2.Series[0]["PieLabelStyle"] = "Outside";
            chart2.Series[0].Legend = "Stores";
            chart2.Legends[0].Docking = Docking.Bottom;
            //loat bieu do trinh do 
            List<TrinhDoPublic> td = TrinhDoBLL.LoadBieuDoTrinhDo();
            chart3.Series["TrinhDo"].Points.DataBindXY(td, "MaTD", td, "SL");
            //chart1.Data
            for (int i = 0; i < chart3.Series[0].Points.Count(); i++)
            {
                chart3.Series[0].Points[i].LegendText = td[i].TenTrinhDo + ": #VALY";
                //chart1.Series[0].Points[i].Label = ;
            }
            chart3.Legends.Add(new Legend("Stores"));
            chart3.Series[0].ChartType = SeriesChartType.Pie;
            chart3.Series[0]["PieLabelStyle"] = "Outside";
            chart3.Series[0]["PieLineColor"] = "Black";

            chart3.Series[0].Label = "#PERCENT{P0}";
            chart3.Series[0].Font = new Font("Segoe UI", 8.0f, FontStyle.Bold);
            chart3.Series[0].ChartType = SeriesChartType.Pie;
            chart3.Series[0]["PieLabelStyle"] = "Outside";
            chart3.Series[0].Legend = "Stores";
            chart3.Legends[0].Docking = Docking.Bottom;
            this.reportViewer1.RefreshReport();
            for (int i = 2005; i <= DateTime.Now.Year; i++)
            {
                
                cmbThoiGianBatDau.Items.Add(i.ToString());
                cmbThoiGianKetThuc.Items.Add(i.ToString());
            }
            cmbThoiGianBatDau.SelectedIndex = -1;
            cmbThoiGianBatDau.Text = "Bắt đầu";
            cmbThoiGianKetThuc.SelectedIndex = -1;
            cmbThoiGianKetThuc.Text = "Đến nay";
            //MessageBox.Show(cmbThoiGianBatDau.Text.ToString());
            
            txtSoSoHoKhau.Text = SoHoKhauBLL.CountSoHoKhau().ToString();
            txtSoNhanKhau.Text = NhanKhauBLL.CountNhanKhau().ToString();
            txtNKNam.Text = NhanKhauBLL.CountNhanKhauNam().ToString();
            txtNKNu.Text = NhanKhauBLL.CountNhanKhauNu().ToString();
            //this.reportViewer1.RefreshReport();

            
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            //var tgbt = dateBatDau.Value;
            //var tgkt = dateKetThuc.Value;
            //this.Age.Series["Nam"].Points.AddXY("A", 11);
            //this.Age.Series["Nam"].Points.AddXY("d", 20);
            //this.Age.Series["Nam"].Points.AddXY("g", 23);
            //this.Age.Series["Nam"].Points.AddXY("s", 34);
        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            int start;
            int and;
            if (cmbThoiGianBatDau.SelectedIndex == -1)
            {
                start = 2005;
            }
            else
            {
                start = int.Parse(cmbThoiGianBatDau.Text);
            }
            if (cmbThoiGianKetThuc.SelectedIndex == -1)
            {
                and = DateTime.Now.Year;
            }
            else
            {
                and = int.Parse(cmbThoiGianKetThuc.Text);
            }
            txtSoSoHoKhau.Text = SoHoKhauBLL.CountSoHoKhauByYear(start, and).ToString();
            txtChuyenDen.Text=ChuyenKhauBLL.CountChuyenDenByYear(start,and).ToString();
            txtChuyenDi.Text = ChuyenKhauBLL.CountChuyenDiByYear(start, and).ToString();

            txtKhaiSinh.Text = KhaiSinhBLL.CountKhaiSinhByYear(start, and).ToString();
            txtKhaiTu.Text = KhaiTuBLL.CountKhaiTuByYear(start, and).ToString();
        }

       

        
    }

}
